import axios from '../../plugins/axios.js'
import formatTime from '../../utils/formatTime.js'

const state = {
	detail:{}  //相当于data:[]
}

const actions = {
	detail : async({state,commit},{_id,collectionName}={})=>{
		//判断payload是不是数组
		let {data} = await axios.get(`/news/${collectionName}/${_id}`)
		//success ?->判断payload是不是对象
		commit('detail',data)
	}
}

const mutations = {
	detail:(state,payload)=>state.detail=payload
}

const getters = {
	cptTime(state){
		return formatTime(state.detail.time)
	}
}

export default {
	namespaced:true,
	state,actions,mutations,getters
}
